<template>
  <div class="home">
    <el-container>
      <el-header>
        <img class="logo" src="../assets/images/后台首页/u1425.png" alt="" />
        <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" background-color="#545c64" text-color="#fff" active-text-color="#fff" router>
          <el-menu-item :index="item.path" v-for="item in NavListData" :key="item.id">{{ item.name }}</el-menu-item>
        </el-menu>
        <el-menu :default-active="activeIndex2" class="el-menu-demo rightList" mode="horizontal" background-color="#545c64" text-color="#fff" active-text-color="#fff">
          <el-menu-item index="1"
            ><img src="../assets/images/后台首页/u137.png" alt="" /> <span class="userName"> {{ username }}</span></el-menu-item
          >
          <el-menu-item index="2"><img src="../assets/images/后台首页/u138.png" alt=""/></el-menu-item>
          <el-menu-item index="3" class="userImg"
            ><img src="../assets/images/后台首页/u140.png" alt="" />
            <img src="../assets/images/后台首页/u141.png" alt="" />
            <img src="../assets/images/后台首页/u142.png" alt="" />
          </el-menu-item>
          <el-menu-item index="4"><img src="../assets/images/后台首页/u143.png" alt=""/></el-menu-item>
          <el-menu-item index="5" @click="logout()"><img src="../assets/images/后台首页/u146.png" alt=""/></el-menu-item>
        </el-menu>
      </el-header>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </div>
</template>
<script>
export default {
  data() {
    return {
      activeIndex: '1',
      activeIndex2: '',
      username: '',
      NavListData: []
    }
  },
  methods: {
    async getNavList() {
      const { data: res } = await this.$http.get('navList')
      if (res.status !== 200) {
        return
      }
      this.NavListData = res.data
      // console.log(res)
    },
    logout() {
      sessionStorage.removeItem('username')
      sessionStorage.removeItem('token')
      this.$router.push('/login')
    }
  },
  created() {
    this.username = sessionStorage.getItem('username')
    this.getNavList()
  }
}
</script>
<style lang="less" scoped>
.home {
  height: 100%;
  .el-header {
    background-color: #595e6c;
    .logo {
      transform: translateY(-10px);
    }
    .el-menu {
      padding-left: 20px;
      display: inline-block;
    }
    .rightList {
      float: right;
      .userName {
        padding-left: 5px;
      }
      .userImg {
        display: flex;
        justify-content: center;
        flex-direction: column;
      }
    }
  }
}
</style>
